package com.refactor.practice;

import com.refactor.practice.movie.Movie;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Enumeration;
import java.util.Vector;

/**
 * @Desc: 顾客类
 * @Author: zoupinluowei@qianxin.com
 * @Date: 2024/9/6 21:56
 * @Since: 2.2.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Customer {

    /**
     * 顾客名称
     */
    private String name;

    /**
     * 顾客租赁集合
     */
    private Vector<Rental> rentals;


    public void addRental(Rental arg) {
        rentals.add(arg);
    }

    public String statement() {
        double totalAmount = 0;
        int frequentRenterPoints = 0;
        Enumeration<Rental> rentals = this.rentals.elements();
        String result = "Rental Record for " + getName() + "\n";
        while (rentals.hasMoreElements()) {
            Rental each = rentals.nextElement();
            int dayRented = each.getDayRented();
            Movie movie = each.getMovie();
            double thisAmount = movie.getMovieType().getAmount(dayRented);
            totalAmount += thisAmount;
            frequentRenterPoints += movie.getMovieType().getPoints(dayRented);

            result += "\t" + each.getMovie().getTitle() +
                    "\t" + thisAmount + "\n";
        }
        //add footer lines
        result += "Amount owed is " + totalAmount + "\n";
        result += "You earned " + frequentRenterPoints +
                " frequent renter points";
        return result;
    }
}
